#include "Client.h"
#include <random>

Client::Client(CallerMachine &callerMachine,int min)
{
    this->No = callerMachine.getCurrentNo();
    // 生成 伪随机数
    random_device rd;
    mt19937 gen(rd());
    // 到达时间 随机数生成
    uniform_int_distribution<> dis(min, 540);
    // 分配性别/业务类型 随机数生成  15*7 = 105 确保几率相同
    uniform_int_distribution<> dis2(0,105);
    this->reachTime = dis(gen);
    this->reachDate = Date(this->reachTime);
    // 分配性别
    if (dis2(gen) % 2 == 0) {
        this->sex = Sex::MAN;
    }
    else {
        this->sex = Sex::WOMAN;
    }
    // 分配业务类型
    if (dis2(gen) % 7 != 0) {
        this->bussinessType = BussinessType::COMMON;
        this->comsumptionTime = dis2(gen) % 5 + 1;
    }
    else {
        this->bussinessType = BussinessType::SPECIAL;
        this->comsumptionTime = dis2(gen) % 15 + 1;
    }
    this->name = "客户" + this->No;

}
Client::Client(){

}
Client::~Client()
{
    //dtor
}
Client::Client(CallerMachine &callerMachine,string name, Sex sex, BussinessType bussinessType, int reachTime, int comsumptionTime) {
    this->No = callerMachine.getCurrentNo();
    this->bussinessType = bussinessType;
    this->reachTime = reachTime;
    this->reachDate = Date(reachTime);
    this->comsumptionTime = comsumptionTime;
    this->name = name;
    this->sex = sex;
}
// 获取到达时间
int Client::getReachTime()
{
    return this->reachTime;
}
// 获取业务类型
BussinessType Client::getBussinessType() {
    return this->bussinessType;
}
// 后去消耗时间
int Client::getComsumptionTime()
{
    return this->comsumptionTime;
}
// 获取等待时间
int Client::getWaitingTime()
{
    return this->waitingTime;
}
// 获取到达日期
Date& Client::getReachDate()
{
    return this->reachDate;
}
// 获取结束日期
Date& Client::getOverDate()
{
    return this->overDate;
}
// 获取姓名
string Client::getName()
{
    return this->name;
}
// 获取结束时间
int Client::getOverTime() {
    return this->overTime;
}
// 设置性别
Sex Client::getSex()
{
    return this->sex;
}
// 获取窗口编号
int Client::getWidgetNo() {
    return this->widgetNo;
}
// 设置到达时间
void Client::setReachTime(int minutes) {
    this->reachTime = minutes;
    this->reachDate = Date(this->reachTime);
}
// 设置等待时间
void Client::setWaitingTime(int minutes) {
    this->waitingTime = minutes;
    this->overTime = this->reachTime + this->waitingTime + this->comsumptionTime;
    this->overDate = Date(this->overTime);
}
// 更新
void Client::update() {
    this->overTime = this->reachTime + this->waitingTime + this->comsumptionTime;
    this->reachDate = Date(this->reachTime);
    this->overDate =  Date(this->overTime);
}
// 获取编号
string Client::getNo() {
    return this->No;
}
// 设置编号
void Client::setNo(string No) {
    this->No = No;
}
// 设置窗口编号
void Client::setWidgetNo(int num) {
    this->widgetNo = num;
}
// 重载>=
bool Client::operator >=(const Client& other)const {
    return this->reachTime >= other.reachTime;
}
// 重载<=
bool Client::operator <=(const Client& other)const {
    return this->reachTime <= other.reachTime;
}
// 返回基本信息（字符串）
string Client::toString() {
    string nameStr = this->getName();
    string noStr = this->getNo();
    string reachTimeStr = std::to_string(this->getReachTime());
    string comsumptionTimeStr = std::to_string(this->getComsumptionTime());
    string bussinessTypeStr = this->getBussinessType() == BussinessType::COMMON ? "COMMON" : "SPECIAL";
    string sexStr = this->getSex() == Sex::MAN ? "MAN" : "WOMAN";
    //string reachDateStr = this->reachDate.getDate()+this->reachDate.getTime();
    return noStr + " " + nameStr + " "+ sexStr +" "+ bussinessTypeStr + " " + reachTimeStr + " " + comsumptionTimeStr;
}
